package com.ruoyi.project.wf.controller;

import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wf.domain.WfActBranch;
import com.ruoyi.project.wf.service.IWfActBranchService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import java.util.Arrays;

import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 流程详情Controller
 *
 * @author XQ.XU
 * @date 2020-04-08
 */
@Controller
@RequestMapping("/wf/wfActBranch")
public class WfActBranchController extends BaseController
{
    private String prefix = "wf/wfActBranch";

    @Autowired
    private IWfActBranchService wfActBranchService;

    @RequiresPermissions("wf:wfActBranch:view")
    @GetMapping()
    public String wfActBranch()
    {
        return prefix + "/wfActBranch";
    }

    /**
     * 查询流程详情列表
     */
    @RequiresPermissions("wf:wfActBranch:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WfActBranch wfActBranch)
    {
        startPage();
        List<WfActBranch> list = wfActBranchService.list(new QueryWrapper<>(wfActBranch));
        return getDataTable(list);
    }

    /**
     * 导出流程详情列表
     */
    @RequiresPermissions("wf:wfActBranch:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WfActBranch wfActBranch)
    {
        List<WfActBranch> list = wfActBranchService.list(new QueryWrapper<>(wfActBranch));
        ExcelUtil<WfActBranch> util = new ExcelUtil<WfActBranch>(WfActBranch.class);
        return util.exportExcel(list, "wfActBranch");
    }

    /**
     * 新增流程详情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存流程详情
     */
    @RequiresPermissions("wf:wfActBranch:add")
    @Log(title = "流程详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WfActBranch wfActBranch)
    {
        return toAjax(wfActBranchService.saveOrUpdate(wfActBranch));
    }

    /**
     * 修改流程详情
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        WfActBranch wfActBranch = wfActBranchService.getById(id);
        mmap.put("wfActBranch", wfActBranch);
        return prefix + "/edit";
    }

    /**
     * 修改保存流程详情
     */
    @RequiresPermissions("wf:wfActBranch:edit")
    @Log(title = "流程详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WfActBranch wfActBranch)
    {
        return toAjax(wfActBranchService.saveOrUpdate(wfActBranch));
    }

    /**
     * 删除流程详情
     */
    @RequiresPermissions("wf:wfActBranch:remove")
    @Log(title = "流程详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wfActBranchService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
